#include <iostream>
#include <cstdio>
using namespace std;
char Matrix[59][59];
int ANS(int n, int m) {
    int res = 0;
    int j=0;
    while (j<m) {
        int cnt = 0;
        for (int k=0; k<=j&&k<n; ++k) {
            char t = Matrix[k][j-k];
//            printf("%c ", t); printf("%d %d\n", k, j-k);
            if ((t=='X'||t=='Y') && cnt) {
                ++res;
 //                printf("%d\n", res);
                cnt=0;
            }
            if (t=='B' || t=='G') ++cnt;
        }
        if (cnt) ++res;
        ++j;
    }
 //    printf("\n");
    j=1;
    while (j<n) {
        int cnt = 0;
        for (int k=j; k<n&&m-1-(k-j)>=0; ++k) {
            char t = Matrix[k][m-1-(k-j)];
 //           printf("%c ", t); printf("%d %d\n", k, m-1-(k-j));
            if ((t=='X'||t=='Y')  && cnt) {
                ++res;
 //                printf("%d\n", res);
                cnt=0;
            }
            if (t=='B' || t=='G') ++cnt;
        }
        if (cnt) ++res;
        ++j;
    }
 //    printf("\n");
    j=0;
    while (j<m) {
        int cnt = 0;
        for (int k=0; k<n&&j+k<m; ++k) {
            char t = Matrix[k][j+k];
 //            printf("%c ", t); printf("%d %d\n", k, j+k);
            if ((t=='X'||t=='B') && cnt) {
                ++res;
 //                printf("%d\n", res);
                cnt=0;
            }
            if (t=='Y' || t=='G') ++cnt;
        }
        if (cnt) ++res;
        ++j;
    }
 //    printf("\n");
    j=1;
    while (j<n) {
        int cnt = 0;
        for (int k=j; k<n&&k-j<m; ++k) {
            char t = Matrix[k][k-j];
 //            printf("%c ", t); printf("%d %d\n", k, k-j);
            if ((t=='X'||t=='B') && cnt) {
                ++res;
 //                printf("%d\n", res);
                cnt = 0;
            }
            if (t=='Y' || t=='G') ++cnt;
        }
        if (cnt) ++res;
        ++j;
    }
 //    printf("\n");
    return res;
}
int main(int argc, char** argv) {
#ifdef hai
    freopen("in1.txt", "r", stdin);
#endif
    int n,m;
    cin>>n>>m;
    for (int i=0; i<n; ++i) {
        scanf("%s", Matrix[i]);
    }
    cout<<ANS(n,m)<<endl;
    return 0;
}
